home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Presentations / Presentations ’97 / Papers ’97 / Rainer Brockerhoff's Two Heads / HydraExample.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-26  |  3.8 KB  |  100 lines  |  [TEXT/CWIE]

  1. #pragma once
  2.  
  3. ///////////////////////////////////////////////////////////////
  4. //    Hydra classes are Copyright ©1997 by Rainer Brockerhoff.
  5. //
  6. //    Submitted as part of the paper :
  7. //    "On Having Two (or More) Heads, or : Real-time Programming in Spite of
  8. //        the MacOS", for MacHack 1997
  9. //
  10. //    This is an example application for illustrating use of the Hydra classes.
  11. //    It seems to run OK on any PowerMac under System 7.5 or later with standard
  12. //    extensions and control panels.
  13. //    It may crash if you open too many windows or have stuff installed which messes
  14. //    with the same system resources that I do. See "Hydra.cp" and "Hydra.h" for
  15. //    the full story.
  16. //    This example uses the least error checking it can get away with.
  17. //
  18. //    You may use the Hydra classes in your application at no cost;
  19. //    however, the application's "About" box should repeat my
  20. //    copyright line as above. Be sure to write my name correctly ;-)
  21. //    I'd also appreciate getting a demo copy of your application.
  22. //    These classes have not been exhaustively tested in this form
  23. //    and all use is at your own risk.
  24. //
  25. //    Contact me at <rainer@machome.com.br> or
  26. //    http://www.machome.com.br/delta/
  27. //
  28. //    Stylistic note :
  29. //    Astute older colleagues will no doubt deduce that in my misspent youth I:
  30. //    1) learned FORTRAN    (short variable names; local variables called i,j,k)
  31. //    2) learned PL/I        (using }; everywhere)
  32. //    3) used punch cards (using {} even when not needed, to more easily insert
  33. //        printf debug lines)
  34. //    4) had too little contact with other programmers and so failed to learn
  35. //        proper indentation, naming or bracing standards.
  36. //    They're probably right on all counts... :-)
  37. //
  38. //    I'm assuming CodeWarrior 12 (or Pro 1) is being used.
  39. //
  40. //    This source file is overcommented, for pedagogical purposes only.
  41.  
  42. enum {                                    // these enums define our window types.
  43.     lines,
  44.     rects
  45. };
  46.  
  47. ///////////////////////////////////////////////////////////////
  48. // Our example application class.
  49. // See HydraExample.cp for details.
  50. //
  51. class    ExampleApp : public HydraApplication, public LListener {
  52. public:
  53.                             ExampleApp();
  54.     virtual                 ~ExampleApp();
  55.     virtual Boolean            ObeyCommand(CommandT inCommand,void* ioParam);    
  56.     virtual void            FindCommandStatus(CommandT inCommand,Boolean &outEnabled,Boolean &outUsesMark,Char16 &outMark,Str255 outName);
  57. protected:
  58.     virtual void            Initialize();
  59.     virtual void            ListenToMessage(MessageT inMessage,void* ioParam);
  60. };
  61.  
  62. ///////////////////////////////////////////////////////////////
  63. // Our example window class.
  64. // See HydraExample.cp for details.
  65. //
  66. class    ExampleWindow : public HydraWindow {
  67. public:
  68.     enum { class_ID = 'Wind' };            // remember to use this in PowerPlant Constructor
  69.     enum { updatesPerSecond = 10 };        // window update frequency
  70.                             ExampleWindow(LStream* inStream);
  71.     virtual                    ~ExampleWindow();
  72.     static ExampleWindow*    CreateWindow(short type,LCommander* inSuperCommander);
  73.     void                    DoUpdate();
  74.     const static short        ;
  75. protected:
  76.     virtual void            FinishCreateSelf();
  77.     virtual void            DrawSelf();
  78.     virtual void            ClickSelf(const SMouseDownEvent& inMouseDown);
  79.     void                    DrawLines(short x,short y);
  80.     void                    DrawRects();
  81.     LSimpleThread*            mThread;    // local window's update thread
  82.     LGWorld*                mGWorld;    // local LGWorld to hold the window's image
  83.     Rect                    mFrame;        // window's frame in local coordinates
  84.     short                    mX,mY;        // center point coordinates
  85.     short                    mState;        // state for 'lines' window
  86.     short                    mIndex;        // index for 'lines' window
  87.     short                    mStep;        // step for 'lines' window
  88.     short                    mHueDelta;    // hue delta for 'lines' window
  89.     HSVColor                mHSV;        // current color
  90.     UInt32                    mLastTime;    // time of last update
  91. };
  92.  
  93. ///////////////////////////////////////////////////////////////
  94. // Global function prototypes.
  95. // See HydraExample.cp for details.
  96. //
  97. void windowThread(LThread& thread,void* arg);
  98. long randomInRange(long from,long to);
  99.  
  100.